package br.com.leopard.erp.gym.web.session;

import java.io.IOException;

import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import javax.inject.Inject;

import br.com.leopard.erp.gym.bean.login.AuthorizationPhaseListener;
import br.com.leopard.erp.gym.session.UsuarioSession;

@ManagedBean
@SessionScoped
public class UsuarioNavegacaoSession {

	@Inject
	private UsuarioSession usuarioSession;

	private String currentPageContent;

	private boolean isHome;

	@PostConstruct
	public void setHome() {
		currentPageContent = "/pages/home.xhtml";
		isHome = true;
	}

	public void redirecionarHomePortal() {
		try {
			String path = FacesContext.getCurrentInstance().getExternalContext().getApplicationContextPath();
			path += AuthorizationPhaseListener.HOME_PAGE_ACESSO_BROWSER;

			FacesContext.getCurrentInstance().getExternalContext().redirect(path);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public void redirecionarPaginaLogin() {
		try {
			String path = FacesContext.getCurrentInstance().getExternalContext().getApplicationContextPath();
			path += AuthorizationPhaseListener.LOGIN_PAGE;

			FacesContext.getCurrentInstance().getExternalContext().redirect(path);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public void recarregarPermissoesUsuario() {
		usuarioSession.recarregarPermissoesUsuario();
		setHome();
	}

	public String getCurrentPageContent() {
		return currentPageContent;
	}

	public void setCurrentPageContent(String currentPageContent) {
		this.currentPageContent = currentPageContent;
		isHome = false;
	}

	public boolean isHome() {
		return isHome;
	}

}
